package me.zhengjie.gas.proto.send;

import me.zhengjie.gas.proto.TankerComm;

/**
 * PC机主动预置加油机加油量或者金额(命令E4H)
 */
public class E4Comm extends TankerComm {
    // 状态字
    private byte STATUS;

    // 预置量
    private int PREAMN;

    public E4Comm() {
        Cmd = (byte) 0xE4;
    }

    @Override
    public byte[] encode() {
        byte[] data = new byte[6];
        data[0] = Cmd;
        data[1] = STATUS;

        // 预置量
        byte a1 = (byte) (PREAMN / 10000000);
        byte a2 = (byte) ((PREAMN % 10000000) / 1000000);
        byte a3 = (byte) ((PREAMN % 1000000) / 100000);
        byte a4 = (byte) ((PREAMN % 100000) / 10000);
        byte a5 = (byte) ((PREAMN % 10000) / 1000);
        byte a6 = (byte) ((PREAMN % 1000) / 100);
        byte a7 = (byte) ((PREAMN % 100) / 10);
        byte a8 = (byte) (PREAMN % 10);
        data[2] = (byte) ((a1 << 4) | a2);
        data[3] = (byte) ((a3 << 4) | a4);
        data[4] = (byte) ((a5 << 4) | a6);
        data[5] = (byte) ((a7 << 4) | a8);


        setDATA(data);
        return super.encode();
    }

    public void setPREAMN(int PREAMN) {
        this.PREAMN = PREAMN;
    }

    public void setSTATUS(byte STATUS) {
        this.STATUS = STATUS;
    }
}
